import logging

from flask import Blueprint, redirect, render_template, session
from flask_restful import Api

from utils.login_helper import check_user_state
from .user_api import login_api, registry_api, get_user_ks_info_api, save_user_ks_info_api, get_user_info_api, \
    save_user_info_api, reset_password_api, get_user_temp_api
from .user_head import get_head_list, change_user_head_api
from .we_api import we_update_api

user_blueprint = Blueprint('user_bp', __name__)

api = Api(user_blueprint)

@user_blueprint.route('/user/home', endpoint="user_home")
@check_user_state
def home():
    logging.info(f"用户({session['email']})请求home页面")
    return render_template('./user/html/index.html')

@user_blueprint.route('/user/option', endpoint="user_option")
@check_user_state
def option():
    return render_template('./user/html/index.html')

@user_blueprint.route('/user/set', endpoint="user_set")
@check_user_state
def set_():
    return render_template('./user/html/index.html')

@user_blueprint.route('/user/head', endpoint="user_head")
def head():
    return render_template('./user/html/index.html')

@user_blueprint.route('/user/login')
def login():
    return render_template('./user/html/index.html')

@user_blueprint.route('/user/registry')
def registry():
    return render_template('./user/html/index.html')

@user_blueprint.route('/user/forgot')
def forgot():
    return render_template('./user/html/index.html')

@user_blueprint.route('/user/chat', endpoint="user_chat")
@check_user_state
def chat_room():
    return render_template('./user/html/index.html')

@user_blueprint.route('/user/count', endpoint="user_count")
@check_user_state
def count_view():
    return render_template('./user/html/index.html')


# api.add_resource(对象, 'url')
api.add_resource(login_api, '/user/api/login')
api.add_resource(registry_api, '/user/api/registry')
api.add_resource(reset_password_api, '/user/api/forgot')

api.add_resource(get_user_ks_info_api, '/user/api/get_user_ks_info_api')
api.add_resource(save_user_ks_info_api, '/user/api/save_user_ks_info_api')

api.add_resource(get_user_info_api, '/user/api/get_user_info_api')
api.add_resource(save_user_info_api, '/user/api/save_user_info_api')

api.add_resource(get_head_list, '/user/api/get_head_list')
api.add_resource(change_user_head_api, '/user/api/change_head')

api.add_resource(we_update_api, '/welcome/api/update')

api.add_resource(get_user_temp_api, '/user/api/get_temp')
